@extends('admin.common.main')
@section('css')
    {{--webuploader样式--}}
    <link rel="stylesheet" type="text/css" href="/webuploader/webuploader.css" />

@endsection
@section('cnt')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span> 用户中心 <span class="c-gray en">&gt;</span> 添加节点 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>

    <article class="page-container">
        @include('admin.common.validate')
        <form action="{{route('admin.fangattr.update',$fangattr)}}" method="post" class="form form-horizontal" id="form-member-add">
            @method('PUT')
            @csrf()
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>是否顶级：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <span class="select-box">
                        <select class="select" name="pid">
                            <option value="0" @if($fangattr->pid==0) selected @endif>==顶级==</option>
                            @foreach($data as $item)
                                <option value="{{$item->id}}" @if($fangattr->pid==$item->id) selected @endif>{{$item->name}}</option>
                            @endforeach
                        </select>
                    </span>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>属性名称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    {{--v-model.lazy 延时绑定--}}
                    <input type="text" class="input-text" placeholder="" name="name" value="{{$fangattr->name}}">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>属性图标：</label>
                <div class="formControls col-xs-4 col-sm-5">
                    <div id="picker">选择图标</div>
                </div>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="hidden"  value="{{$fangattr->icon}}" name="icon" id="icon">
                    <img src="{{$fangattr->icon}}" id="pic" style="width: 50px">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">字段名称：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text"  placeholder=""  name="field_name" value="{{$fangattr->field_name}}">
                </div>
            </div>

            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="提交">
                </div>
            </div>
        </form>
    </article>
    @endsection
@section('js')
    <script src="/webuploader/webuploader.js"></script>

    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>

    <script>
        $('#form-member-add').validate({
            rules:{
                name:{
                    required:true
                },
                field_name:{
                    required:false
                },
            },
            massage:{
                name: {
                   required: '名字要写',
                },
            },
            onkeyup:false, //取消键盘时间
            // focusCleanup:true,
            success:"valid", //验证成功样式
            //验证通过后，处理的方法，form dom对象
            submitHandler:function(form){
                //表单提交
               form.submit();
            }
        });


        var uploader = WebUploader.create({
            //选完文件自动上传
            auto:true,
            // swf文件路径
            swf: '/webuploader/js/Uploader.swf',

            // 文件接收服务端。
            server: '{{route('admin.fangattr.upfile')}}',
            //文件参数
            formData:{
                _token: '{{csrf_token()}}'
            },
            //文件上传表单名称
            fileVal:'file',

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick:{
                id:'#picker',
                //是否开启选择多文件能力
                multiple:false,
            } ,

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false
        });
        // 文件上传成功，给item添加成功class, 用样式标记上传成功。回调方法
        uploader.on( 'uploadSuccess', function( file ,ret) {
            let src = ret.url;

            //给表单添加value值
            $("#icon").val(src);
            //给图片添加
            $('#pic').attr('src',src);
        });
    </script>

    @endsection